import Tkinter
from twisted.internet import tksupport,reactor
from twisted.web.client import getPage
from twisted.python.util import println

urls=['http://www.baidu.com/',
      'http://zhidao.baidu.com/',
      'http://mp3.baidu.com/',
      'http://aatieba.baidu.com/'      
      ]
def get_next_page(*t,**kw):
    while urls:
        get_page(urls.pop())
def print_msg(*msg,**karg):
    pass
def handle_err(err):
    print err
def get_page(url):
    d=getPage(url).addCallbacks(
        callback=print_msg,
        errback=handle_err).addBoth(get_next_page)
    print 'get:'+url
get_next_page()

def start():
    print 'start'
def stop():
    reactor.stop()
    print 'stop'
root=Tkinter.Tk()
tksupport.install(root)
#root.geometry('100x150')

f = Tkinter.Frame(root)
b_start=Tkinter.Button(f,text='start',command=start)
b_start.config(height=3,width=10)
b_start.pack()
b_stop=Tkinter.Button(f,text='stop',height=3,width=10,command=stop)
b_stop.pack()

#f.pack(side=Tkinter.RIGHT)
f.pack()



#Tkinter.mainloop()

print 'reactor'
reactor.run()



print 'end'
